import React, { PureComponent } from 'react';
import { Form, Input, Select, Modal } from 'antd';
const FormItem = Form.Item;
const Option = Select.Option;
class CustomizedForm extends PureComponent {
  constructor(props) {
    super(props);
  }
  okHandle = () => {
    const { form, handleAdd ,SelectObj} = this.props;
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      form.resetFields();
      let data;
      if (Object.prototype.toString.call(SelectObj) == "[object Object]"){
        data = {
          ...fieldsValue,
          pid: SelectObj.id
        }
      }
      if (Object.prototype.toString.call(SelectObj) == "[object Array]"){
        data = {
          ...fieldsValue,
          pid: 0
        }
      }
      handleAdd(data);
    });
  };
  render() {
    const { modalVisible, form, handleModalVisible, orginize } = this.props;
    return (
      <Modal
        destroyOnClose //关闭时销毁 Modal 里的子元素
        title="新增组织信息"
        visible={modalVisible}
        onOk={this.okHandle}
        onCancel={() => handleModalVisible()}
      >
        <FormItem labelCol={{ span: 6 }} wrapperCol={{ span: 15 }} label="菜单名称">
          {form.getFieldDecorator('name', {
            rules: [{ required: true, message: '请输入菜单名称' }],
            initialValue: '',
          })(<Input placeholder="请输入" />)}
        </FormItem>
        <FormItem labelCol={{ span: 6 }} wrapperCol={{ span: 15 }} label="所属组织">
          {form.getFieldDecorator('666', {
            initialValue: orginize ? orginize: '全部',
          })(<Input placeholder="请输入" disabled />)}
        </FormItem>
        <FormItem labelCol={{ span: 6 }} wrapperCol={{ span: 15 }} label="组织类型">
          {form.getFieldDecorator('orgType', {
            rules: [{ required: true}],
            initialValue: 1,
          })(
            <Select style={{width:"100%"}}>
              <Option value={1}>公司</Option>
              <Option value={2}>车队</Option>
            </Select>
          )}
        </FormItem>
      </Modal>
    );
  }
}
const CreateForm = Form.create()(CustomizedForm);

export default CreateForm;
